package xyz.xtgl.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import common.core.util.LoginUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import plus.handler.LogicMetaObjectHandler;
import plus.handler.LogicMetaObjectHandlerService;
import plus.handler.PageConverter;
import plus.handler.QueryWrapperConverter;

/**
 * @author liubo
 * @created 2020-01-01 18:56
 */
@Configuration
public class MyBatisPlusConfiguration {

    @Bean
    public PageConverter pageConverter(){
        return new PageConverter();
    }

    @Bean
    public QueryWrapperConverter queryWrapperConverter(){
        return new QueryWrapperConverter();
    }

    @Bean
    public LogicMetaObjectHandlerService logicMetaObjectHandlerService(){
        return new LogicMetaObjectHandlerService(){
            @Override
            public String getOperator() {
                return LoginUtil.getUsername();
            }
        };
    }

    @Bean
    public LogicMetaObjectHandler logicMetaObjectHandler(){
        return new LogicMetaObjectHandler(logicMetaObjectHandlerService());
    }

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        return paginationInterceptor;
    }
}